<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta content="width=device-width,initial-scale=1.0,user-scalable=yes" name="viewport"/>
    <title>用户手册</title>
    <style>
        img{
            width: 100%;
            height: auto;
        }
    </style>
</head>
<body onload="pageLoad();">

</body>
<script type="text/javascript">
    const baseUrl = 'https://car.cq-ct.com:8901';
    function pageLoad(){
        let search = window.location.search.substr(1);
        let temp = search.split('&');
        let params = {};
        temp.forEach(item => {
            if(item.indexOf('token=') != -1){
                params.token = item.substr(6);
            }
            if(item.indexOf('cTypeId=') != -1){
                params.id = item.substr(8);
            }
        });
        getData(params);
    }

    function getData(param) {
        request('/iot-device-saas-car/cartype/detail?id='+param.id,param.token,'get',(res) => {
            console.log(res);
            let data = res.data;
            let append = data.userHandbook || '';
            let div = document.createElement('div');
            div.innerHTML = append;
            document.body.append(div);
        });
    }

    function request(_url,token,method,func){
        let xhr = new XMLHttpRequest();
        xhr.open(method, baseUrl + _url,true);
        xhr.onreadystatechange = function(){
            if(this.readyState !== 4) return;
            if(this.status === 200){
                func(this.response);
            }else{
                console.log(this.statusText);
            }
        }

        xhr.onerror = function (e) {
            console.log(this.statusText);
        }

        xhr.responseType = "json";
        xhr.setRequestHeader('Accept','application/json');
        xhr.setRequestHeader('Authorization','Basic c2FiZXI6c2FiZXJfc2VjcmV0');
        xhr.setRequestHeader('Blade-Auth','bearer ' + token);
        xhr.send();
    }
</script>
</html>